<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Provinsi extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		if((!$this->session->userdata('user_display')) && (!$this->session->userdata('id_user'))):
			redirect('login');
		endif;
		
		$this->load->model('Common_model');
	}

	function index()
	{
		$offset = $this->uri->segment(3);
		$config['base_url'] = site_url().'/provinsi/index';
		$config['total_rows'] = count($this->Common_model->getData('list','tb_provinsi',FALSE,FALSE,FALSE,FALSE));
		$config['per_page'] = $this->config->item('per_page');
		$config['uri_segment'] = '3';
		$data['urut'] = $this->uri->segment(3);
		$data['slug'] = anchor('provinsi','Data Provinsi');
		$data['title'] = "Data Provinsi";
		$data['query'] = $this->Common_model->getData('list','tb_provinsi',FALSE,FALSE,$config['per_page'],$offset);
		$data['main_view'] = "provinsi/index";
		$this->pagination->initialize($config);
		$this->load->view('index',$data);
	}
	
	function add()
	{
		$this->form_validation->set_rules('nama_provinsi', 'Nama provinsi','required');

		if($this->form_validation->run() == FALSE)
		{
			$data['slug'] = anchor('provinsi','Data Provinsi').' &raquo; '.'Tambah Data Provinsi';
			$data['title'] = 'Tambah Data Provinsi';
			$data['main_view'] = "provinsi/add";
			$this->load->view('index',$data);
		}
		else
		{
			$data = array(
					'nama_provinsi'=>$this->input->post('nama_provinsi')
					);
			$this->Common_model->addData('tb_provinsi',$data);
			redirect('provinsi');
		}
	
	}
	
	function edit()
	{
		$this->form_validation->set_rules('nama_provinsi', 'Nama provinsi','required');

		if($this->form_validation->run() == FALSE)
		{
			$id = $this->uri->segment(3);
			$data['slug'] = anchor('provinsi','Data Provinsi').' &raquo; '.'Edit Data Provinsi';
			$data['title'] = 'Edit Data Provinsi';
			$data['main_view'] = "provinsi/edit";
			$data['row'] = $this->Common_model->getData('by_id','tb_provinsi','id_provinsi',$id,FALSE,FALSE);
			$this->load->view('index',$data);
		}
		else
		{
			$id = $this->uri->segment(3);
			$data = array(
					'nama_provinsi'=>$this->input->post('nama_provinsi')
					);
			$this->Common_model->editData('tb_provinsi','id_provinsi',$id,$data);
			redirect('provinsi');
		}
	
	}
	
	function delete()
	{
		$id = $this->uri->segment(3);
		$this->Common_model->deleteData('tb_provinsi','id_provinsi',$id);
		redirect('provinsi');
	}
}

/* End of file provinsi.php */
/* Location: ./application/controllers/provinsi.php */